package com.controller;


import java.util.List;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import com.beans.User;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 古嘉琦
 * @since 2023-10-12
 */
@Controller
@RequestMapping("/users")
public class UserController {
    
	
    /*
       (UserID=1,Username="古嘉琦",Password="200251",Avatar=null,Contact="13590604201",Address="哈尔滨师范大学");
      
    }*/
	@RequestMapping("/add-user")
    public String myPage() {
        return "add-user"; // 返回逻辑视图名称
    }
	@PostMapping("/add")
    public ResponseEntity<String> addUser(@RequestBody User user) {
        boolean success = user.insert();

        if (success) {
            return ResponseEntity.ok("User added successfully");
        } else {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to add user");
        }
    }

    @RequestMapping("/gotoLogin")
    public String gotoLogin() {
        return "login";
    }
}

